<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[{ name: 'box-base', title: '编号规则' },{ name: 'box-info', title: '主体管理' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">编号规则</div>
          <customFormItem label="识别码" name="ruleCode" :parent="_self" :form="form" />
          <customFormItem label="编码名称" name="name" :parent="_self" :form="form" />
          <customFormItem label="编码段数量" name="partNum" :parent="_self" :form="form"  :type="constCommon.formItemType.inputNumber.name"/>
          <customFormItem label="分隔符" name="delimiter" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.serialDelimiter}"
          />

          <customFormItem label="编码段1表达式" name="part1Cond" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.seriaCond}"
          />
          <customFormItem label=" 编码段1字符串" name="part1" :parent="_self" :form="form" />
          <customFormItem label="编码段2表达式" name="part2Cond" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.seriaCond}"
          />
          <customFormItem label="编码段2表达式" name="part2" :parent="_self" :form="form" />

          <customFormItem label="编码段3表达式" name="part3Cond" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.seriaCond}"
          />
          <customFormItem label=" 编码段3字符串" name="part3" :parent="_self" :form="form" />
          <customFormItem label="编码段4表达式" name="part4Cond" :parent="_self" :form="form"
                          :type="constCommon.formItemType.selectDict.name"
                          :config="{dictType: constCommon.dictType.seriaCond}"
          />
          <customFormItem label=" 编码段4字符串" name="part4" :parent="_self" :form="form" />


          <div id="box-info" class="box-title">主体管理</div>
          <data-view
            propViewKey="serial_owners_crud"
            :propIsTdesign="true"
            :propParentPage="_self"
            ref="childDataView"
            :propAutoFetchData="false"
            @edit-input="rowEditInput"
          />

        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  help: '编号规则-详情',
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    // 加载主体管理数据
    fetchChildData() {
      let queryWrapper = this.$newWrapper()
      if (this.form.id) {
        queryWrapper.eq('ruleId', this.form.id)
      } else {
        queryWrapper.ne(1, 1)
      }
      this.$refs.childDataView.setQueryWrapper(queryWrapper)
    },
    rowEditInput({row}) {
      this.$set(row, 'ruleId', this.form.id)
    },
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        this.viewData = this.propCurrentRow
        this.fetchChildData()
      },
      afterSave: () => {
      },
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {
      },
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {
      },
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: { customAnchor },
  computed: {},
}
</script>
